﻿using TrueSync;

namespace HEFramework
{
    public class Numeric
    {
        /// <summary>
        /// 结算数值
        /// </summary>
        public FP Value { get; private set; }

        /// <summary>
        /// 基础数值
        /// </summary>
        public FP BaseValue { get; private set; }

        /// <summary>
        /// 固定加成
        /// </summary>
        public FP Add { get; private set; }

        /// <summary>
        /// 百分比加成
        /// </summary>
        public FP PctAdd { get; private set; }

        /// <summary>
        /// 最终固定加成
        /// </summary>
        public FP FinalAdd { get; private set; }

        /// <summary>
        /// 最终百分比加成
        /// </summary>
        public FP FinalPctAdd { get; private set; }


        public Numeric(FP _value)
        {
            BaseValue = Add = PctAdd = FinalAdd = FinalPctAdd = 0;
            BaseValue = _value;
            Update();
        }

        public void ChangeBase(FP _value)
        {
            BaseValue += _value;
            Update();
        }

        public void ChangeAdd(FP _value)
        {
            Add += _value;
            Update();
        }

        public void ChangePctAdd(FP _value)
        {
            PctAdd += _value;
            Update();
        }

        public void ChangeFinalAdd(FP _value)
        {
            FinalAdd += _value;
            Update();
        }

        public void ChangeFinalPctAdd(FP _value)
        {
            FinalPctAdd += _value;
            Update();
        }


        private void Update()
        {
            FP value1 = BaseValue;
            FP value2 = (value1 + Add) * (100 + PctAdd) / 100;
            FP value3 = (value2 + FinalAdd) * (100 + FinalPctAdd) / 100;
            Value = value3;
        }
    }
}